import { setStorage, getStorage } from "./common/storage"

/**
 * 生成uuid
 * @returns 
 */
const generateUUID = () => {
  /*
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
    const r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
    return v.toString(16);
  });
  */
 return "123abc"
}

const DEVICE_ID_KEY = "painter-deviceID";

/**
 * 获取设备id
 * @returns string
 */
export const getDeviceId = () => {
  const storedDeviceId = getStorage(DEVICE_ID_KEY)
  if (!storedDeviceId) {
    const newDeviceId = generateUUID();
    setStorage(DEVICE_ID_KEY, newDeviceId)
    return newDeviceId
  }
  return storedDeviceId;
}